/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package swingDemoEvent;

import java.awt.FlowLayout;
import java.awt.TextField;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JComboBox;
import javax.swing.JFrame;

/**
 *
 * @author Administrator
 */
public class JComboBoxTest extends JFrame
        implements ItemListener {

    JComboBox cityChooser;
    TextField text1;

    public JComboBoxTest() {
        text1 = new TextField("city");
        cityChooser = new JComboBox();
        cityChooser.addItem("北京");
        cityChooser.addItem("上海");
        cityChooser.addItem("大连");
        // cityChooser.insert("哈尔滨", 2);
        add(cityChooser);
        add(text1);
        cityChooser.addItemListener(this);
        setLayout(new FlowLayout());
        setVisible(true);
        setSize(300, 300);
        
    }
    public void itemStateChanged(ItemEvent e) {
        text1.setText((String) cityChooser.getSelectedItem());
    }

    public static void main(String args[]) {
        new JComboBoxTest();
    }
}
